using UnityEngine;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
public GUISkin guiskin;
//~ public GUIStyle closedButton;
public GUIStyle boxbg;
public int Int_F; //快捷键
string [] Str=new string[]{"F1","F2","F3"};
public int Int_commodity;
string [] Str_commodity=new string[]{"物品1","物品2","物品3","物品4","物品5","物品6",};
//定义道具栏面板变量
public Texture img;
Vector2 prop=new Vector2(0,100);
public Texture img1;
Vector2 prop1=new Vector2(50,100);
public Texture img2;
Vector2 prop2=new Vector2(100,100);
public Texture img3;
Vector2 prop3=new Vector2(150,100);
public Texture img4;
Vector2 prop4=new Vector2(200,100);
public Texture img5;
Vector2 prop5=new Vector2(250,100);
public Texture img6;
Vector2 prop6=new Vector2(300,100);
//———————————
//定义快捷键面板变量
public Texture imgF1;
Vector2 temp1=new Vector2(0,0);
public Texture imgF2;
Vector2 temp2=new Vector2(50,0);
public Texture imgF3;
Vector2 temp3=new Vector2(100,0);
//———————————
Vector2 second = Vector2.zero;
int Int_img;
Texture [] Str_img;
// Use this for initialization
void Start () {
Str_img=new Texture[]{img1,img2,img3,img4,img5,img6};
imgF1=imgF2=imgF3=img;
}
void Update () {
}
void OnGUI() {
GUI.skin=guiskin;
//道具
GUI.Button (new Rect(prop1.x,prop1.y,50,50), img1);
GUI.Button (new Rect(prop2.x,prop2.y,50,50), img2);
GUI.Button (new Rect(prop3.x,prop3.y,50,50), img3);
GUI.Button (new Rect(prop4.x,prop4.y,50,50), img4);
GUI.Button (new Rect(prop5.x,prop5.y,50,50), img5);
GUI.Button (new Rect(prop6.x,prop6.y,50,50), img6);
GUI.BeginGroup (new Rect(0,0,200,250)); //快捷键
GUI.Button (new Rect(temp1.x,temp1.y,50,50), imgF1);
GUI.Button (new Rect(temp2.x,temp2.y,50,50), imgF2);
GUI.Button (new Rect(temp3.x,temp3.y,50,50), imgF3);
GUI.EndGroup();
chuanru();
if(KJJ(Int_commodity)&&Input.GetKeyUp(KeyCode.Mouse0))
{
if(second.x>temp1.x&&second.y>temp1.y&&second.x<(temp1.x+50)&&second.y<(temp1.y+50))
{
imgF1=KJJ(Int_commodity);
Int_commodity=-1;
}
else if(second.x>temp2.x&&second.y>temp2.y&&second.x<(temp2.x+50)&&second.y<(temp2.y+50))
{
imgF2=KJJ(Int_commodity);
Int_commodity=-1;
}
else if(second.x>temp3.x&&second.y>temp3.y&&second.x<(temp3.x+50)&&second.y<(temp3.y+50))
{
imgF3=KJJ(Int_commodity);
Int_commodity=-1;
}
else if(Input.GetKeyUp(KeyCode.Mouse0))
{
Int_commodity=-1;
}
}
}
int chuanru()
{
second = Event.current.mousePosition;
if(second.x>prop1.x&&second.y>prop1.y&&second.x<(prop1.x+50)&&second.y<(prop1.y+50)&&Input.GetKey(KeyCode.Mouse0))
{
Int_commodity=0;
}
else if(second.x>prop2.x&&second.y>prop2.y&&second.x<(prop2.x+50)&&second.y<(prop2.y+50)&&Input.GetKey(KeyCode.Mouse0))
{
Int_commodity=1;
}
else if(second.x>prop3.x&&second.y>prop3.y&&second.x<(prop3.x+50)&&second.y<(prop3.y+50)&&Input.GetKey(KeyCode.Mouse0))
{
Int_commodity=2;
}
else if(second.x>prop4.x&&second.y>prop4.y&&second.x<(prop4.x+50)&&second.y<(prop4.y+50)&&Input.GetKey(KeyCode.Mouse0))
{
Int_commodity=3;
}
else if(second.x>prop5.x&&second.y>prop5.y&&second.x<(prop5.x+50)&&second.y<(prop5.y+50)&&Input.GetKey(KeyCode.Mouse0))
{
Int_commodity=4;
}
else if(second.x>prop6.x&&second.y>prop6.y&&second.x<(prop6.x+50)&&second.y<(prop6.y+50)&&Input.GetKey(KeyCode.Mouse0))
{
Int_commodity=5;
}
return Int_commodity;
}
Texture KJJ(int ABC)
{
Texture img_img=new Texture();
switch (ABC)
{
case 0:
img_img=img1;
break;
case 1:
img_img=img2;
break;
case 2:
img_img=img3;
break;
case 3:
img_img=img4;
break;
case 4:
img_img=img5;
break;
case 5:
img_img=img6;
break;
}
second = Event.current.mousePosition ;
GUI.Label(new Rect(second.x,second.y,50,50),img_img);
return img_img;
}
}